import { Player } from "./base.js";
import { GIF } from "../utils/gif.js";


export class Kyo extends Player {
    constructor(root, info) {
        super(root, info);

        this.init_animations();
    }

    init_animations() {
        let outer = this;
        let offset_y = [0, -22, -22, -140, 0, 0, 0];
        let frame_rate = [6, 6, 6, 4, 6, 6, 6];

        for (let i = 0; i < Kyo.PIC_NUM; ++i) {
            let gif = new GIF();
            gif.load(`/static/image/player/kyo/${i}.gif`);
            this.animations.set(i, {
                gif: gif,
                frame_cnt: 0, // 总帧数
                frame_rate: frame_rate[i], // 每frame_rate帧后渲染gif的下一帧
                offset_y: offset_y[i],
                scale: 2, 
                loaded: false
            })

            gif.onload = function () {
                let obj = outer.animations.get(i);
                obj.frame_cnt = gif.frames.length;
                obj.loaded = true;
            }
        }

    }
}

Kyo.PIC_NUM = 7;